import { DrawStrategy } from "./DrawStrategies";
import { DrawStrategyFactory } from "./DrawStrategyFactory";

// ToolManager.ts
export type ToolType = 'rectFrame' | 'hexFrame' | 'horizontalMullion' | 'verticalMullion' | 'swing' | 'sliding' | 'oneglass' | 'twoglass' | 'threeglass' | 'cornerJoin' | 'glassJoin' | null;
export type SubCategory = { tool: ToolType; icon: string; name: string };

export class ToolManager {
  private activeTool: ToolType = null;
  private activeStrategy: DrawStrategy | null = null; // 修改为 DrawStrategy 类型
  private categories: { [key: string]: SubCategory[] } = {
    frame: [
      { tool: 'rectFrame', icon: 'https://s2.loli.net/2024/11/01/IF8KDHyj2kRSsxm.png', name: '矩形框' },
      { tool: 'hexFrame', icon: 'https://s2.loli.net/2024/11/07/gYrCt9j2UGDXdaZ.png', name: '异形框' }
    ],
    mullion: [
      { tool: 'horizontalMullion', icon: 'https://s2.loli.net/2024/11/07/XLSvasgytJ5F71l.png', name: '横梃' },
      { tool: 'verticalMullion', icon: 'https://s2.loli.net/2024/11/07/MYgEQvBjhSrRwHb.png', name: '竖梃' }
    ],
    window: [
      { tool: 'swing', icon: 'https://s2.loli.net/2024/11/07/4IYo1uQLOAThwkG.png', name: '平开' },
      { tool: 'sliding', icon: 'https://s2.loli.net/2024/11/07/zY59PSo7gFv8TR3.png', name: '推拉' }
    ],
    glass:[
      { tool: 'oneglass', icon: 'https://s2.loli.net/2024/11/07/JF2XDEpPvGudLTA.png', name: '单玻璃' },
      { tool: 'twoglass', icon: 'https://s2.loli.net/2024/11/07/nmxt7CoUMTb9pAq.png', name: '双玻璃' },
      { tool: 'threeglass', icon: 'https://s2.loli.net/2024/11/07/OL4ovhtg3UQJIeK.png', name: '三玻璃' }
    ],
    corner: [
      { tool: 'cornerJoin', icon: 'https://s2.loli.net/2024/11/01/Zpz7wNbrqEXuvFc.png', name: '转角' }
    ],
    join: [
      { tool: 'glassJoin', icon: 'https://s2.loli.net/2024/11/01/n18wOhoZJbcAmNq.png', name: '拼接' }
    ]
  };

  setTool(tool: ToolType) {
    this.activeTool = tool;
    this.activeStrategy = null;
  }

  getTool(): ToolType {
    return this.activeTool;
  }

  getSubCategories(category: string): SubCategory[] {
    return this.categories[category] || [];
  }

  getDrawStrategy(): DrawStrategy | null {
    if (this.activeStrategy) {
      return this.activeStrategy;
    }
    if (this.activeTool) {
      this.activeStrategy =  DrawStrategyFactory.createStrategy(this.activeTool);
      return this.activeStrategy;
    }
    return null;
  }

  resetTool() {
    this.activeTool = null;
  }
}
